package com.baihan.angus.app.game.busshow.adps;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.baihan.angus.app.game.basic.BaseApplication;
import com.baihan.angus.app.game.basic.base.BaseAdp;
import com.baihan.angus.app.game.basic.utils.ComUtil;
import com.baihan.angus.app.game.busshow.R;

public class ClueDialogTitleAdp extends BaseAdp<String, ClueDialogTitleAdp.ViewHolder> {

    private OnItemClickListener mOnItemClickListener;
    private int thisPosition;

    @Override
    protected RecyclerView.ViewHolder createYourViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_script_dialog_title, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void bindYourViewHolder(@NonNull ViewHolder holder, int position) {
        ViewHolder vh = (ViewHolder) holder;

        String title = getItem(position);

        if (!TextUtils.isEmpty(title)) {
            vh.tvClueTitle.setText(title);
        }

        if (position == getthisPosition()) {
            vh.tvClueTitle.setTextColor(BaseApplication.getApplication().getColor(R.color.appColor));
            vh.tvClueTitle.setWidth(ComUtil.Dp2Px(BaseApplication.getApplication().getApplicationContext(), 102));
            vh.tvClueTitle.setBackgroundResource(R.mipmap.ic_dialog_tab_selected);
        } else {
            vh.tvClueTitle.setTextColor(BaseApplication.getApplication().getColor(R.color.textColor17));
            vh.tvClueTitle.setWidth(ComUtil.Dp2Px(BaseApplication.getApplication().getApplicationContext(), 90));
            vh.tvClueTitle.setBackgroundResource(R.mipmap.ic_dialog_tab_unselected);
        }

        vh.tvClueTitle.setOnClickListener(view -> {
            mOnItemClickListener.onItemClick(position);
        });
    }

    @Override
    protected int getEmptyView() {
        return 0;
    }

    public int getthisPosition() {
        return thisPosition;
    }

    public void setThisPosition(int thisPosition) {
        this.thisPosition = thisPosition;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvClueTitle;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvClueTitle = itemView.findViewById(R.id.tvStoryTitle);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}
